package org.example.fancystudy.LockSupport;

import java.util.concurrent.TimeUnit;

/**
 * @author chaigq
 * @version 1.0
 * @date 2022/11/11 09:58
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        Object o = new Object();
        Thread thread = new Thread(() -> {
            synchronized (o){
                System.out.println(Thread.currentThread().getName() + "come in!");
                try{
                    o.wait();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        }, "thread");
        thread.start();

        try {
            TimeUnit.SECONDS.sleep(2);
        }catch (InterruptedException e){
            e.printStackTrace();
        }

        new Thread(() -> {
            synchronized (o){
                o.notify();
            }
            System.out.println(Thread.currentThread().getName() + "唤醒！");
        }, "thread2").start();
    }
}
